package com.tony.pmp.server.exception;

import com.tony.pmp.common.response.BaseResponse;
import com.tony.pmp.common.response.StatusCode;
import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: CommonExceptionHandler
 * @Auther: 皮蛋布丁
 * @Date: 2021/07/28/21:56
 * @Description: 通用异常处理
 */
@RestControllerAdvice
public class CommonExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(CommonExceptionHandler.class);

    /**
    * @Description: handleAuthorizationException 处理访问未经授权的异常
    * @Param: [e]
    * @return: com.tony.pmp.common.response.BaseResponse
    * @Author: 皮蛋布丁
    * @Date: 2021/7/28 22:07
    */
    @ExceptionHandler(AuthorizationException.class)
    public BaseResponse handleAuthorizationException(AuthorizationException e) {
        log.info("访问了未经授权的操作或资源",e.fillInStackTrace());
        return new BaseResponse(StatusCode.CurrUserHasNotPermission);
    }

}
